package com.zhuhai.controller;


import com.zhuhai.service.PnrService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * pnr
 *  @author zhuhai
 *  @version 1.0.0.0
 */
@Controller
@RequestMapping(value = "pnr")
public class PnrController {
    @Resource
    private PnrService pnrService;

    /**
     * 查询Pnr列表
     * http://localhost:8080/pnr/list
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping(path = "/list")
    @ResponseBody
    public Object getAllPnr(@RequestParam(defaultValue = "0") final int page, @RequestParam(defaultValue = "10") final int pageSize) {
        final Pageable pageable = PageRequest.of(page, pageSize);
        return pnrService.getPnrList( pageable).getContent();
    }

    /**
     * 使用@EntityGraph解决查询pnr信息并获取关联旅客信息时的N+1问题，并对比前后执行的sql，同时截图。
     * http://localhost:8080/pnr/73343
     * @param id
     * @return
     */
    @GetMapping(path = "/{id}")
    @ResponseBody
    public Object getPnr(@PathVariable final  Integer id) {
        return pnrService.getPnr(id);
    }
}
